package com.qiguliuxing.dts.admin.web;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.alibaba.fastjson.JSON;
import com.qiguliuxing.dts.admin.job.OrderJob;
import com.qiguliuxing.dts.admin.service.AdminBrandService;
import com.qiguliuxing.dts.admin.service.AdminOrderService;
import com.qiguliuxing.dts.admin.util.AuthSupport;
import com.qiguliuxing.dts.core.express.ExpressService;
import com.qiguliuxing.dts.core.notify.NotifyService;
import com.qiguliuxing.dts.core.notify.NotifyType;
import com.qiguliuxing.dts.core.qcode.QCodeService;
import com.qiguliuxing.dts.db.service.DtsBrandService;
import com.qiguliuxing.dts.db.service.DtsCategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Description TODO
 * @Author: wenji.song
 * @Date: 2020/11/2 11:01
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/test")
public class TestController {

    @Autowired
    private ExpressService expressService;

    @Autowired
    private NotifyService notifyService;

    /*@RequestMapping
    public void testCaptcha() {
        String phone = "15313388870";
        String[] params = new String[]{"圆通快递", "YT20201999897"};

        SmsResult smsResult = notifyService.notifySmsTemplate(phone, NotifyType.SHIP, params);
        System.out.print("*****腾讯云短信发送->请求验证码，短信发送结果：" + JSONObject.toJSONString(smsResult));
    }*/
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);
    @Autowired
    private DtsBrandService brandService;

    @Autowired
    private DtsCategoryService categoryService;

    @Autowired
    private AdminBrandService adminBrandService;

    @Autowired
    private QCodeService qCodeService;


    /*@PostMapping
    public Object create(@RequestBody DtsBrand brand) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 商场管理->品牌管理->添加,请求参数:{}", JSONObject.toJSONString(brand));
        *//*Object error = validate(brand);
        if (error != null) {
            return error;
        }*//*

        try {
            //生成店铺的分享URL
            String defaultCategory = brandService.getBrandCategory(brand.getDefaultCategoryId());
            String shareUrl = qCodeService.createBrandImage(null,brand.getId(), brand.getPicUrl(), brand.getName(),defaultCategory);
            brand.setShareUrl(shareUrl);
        } catch (Exception e) {
            logger.error("生成品牌商铺分享图URL出错：{}",e.getMessage());
            e.printStackTrace();
        }

        brandService.add(brand);
        logger.info("【请求结束】商场管理->品牌管理->添加:响应结果:{}", JSONObject.toJSONString(brand));
        return ResponseUtil.ok(brand);
    }*/

    /*@RequestMapping
    public void test() {
        ExpressInfoV1 ei = null;
        try {
            ei = expressService.getExpressInfo("YTO", "YT2098143390812");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.print(ei);
    }*/

    @Autowired
    WxMaService wxMaService;

    @RequestMapping("test1")
    public void test1() {
        //String code = CharUtil.getRandomNum(6);
        //SmsResult smsResult = notifyService.notifySmsTemplate("15313388870", NotifyType.CAPTCHA, new String[]{code});
        /*if (smsResult != null) {
            logger.info("*****腾讯云短信发送->请求验证码，短信发送结果：{}", JSONObject.toJSONString(smsResult));
        }*/
        notifyService.notifyWxTemplate("o1GfP4iE29BqesNP_8NuCpddP3O0", NotifyType.PAY_SUCCEED, new String[]{"西瓜", "12.99", "2020-11-01 12:00:00"});
    }

    @Autowired
    private AdminOrderService adminOrderService;

    @RequestMapping("test2")
    public Object verifyAccounting(Date startTime, Date endTime, @RequestParam(value = "list") List<Integer> brandIdList) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 商户对账->startTime:{},endTime:{},body:{}", startTime, endTime, brandIdList);
        return null;
    }

    @RequestMapping("test3")
    public void test3() {
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream("C:\\workspace\\项目demo\\dts-shop - 后端\\dts-core\\src\\main\\resources\\back.png");
            qCodeService.drawPicture(inputStream, "https://www.baidu.com", "测试", new BigDecimal(39.000).setScale(2), new BigDecimal(11.000).setScale(2), new BigDecimal(99.9));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/test4")
    public Object test4(String startTime, String endTime, Integer brandId) {
        Object obj = adminOrderService.verifyAccounting(startTime, endTime, brandId);
        System.out.println(JSON.toJSONString(obj));
        return obj;
    }

    @Autowired
    private OrderJob orderJob;

    @RequestMapping("test5")
    public void test5() {
        orderJob.checkOrderUnconfirm();
    }


}
